﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Jayden.Dll.XmlScript.Descriptions
{
	public abstract class XmlBinaryOperatorDescription<T> : XmlExpressionDescription where T: XmlBinaryExpression, new()
	{
		public XmlExpression Load(XmlScriptLoader loader, XmlElement element)
		{
			T token = new T();
			foreach (XmlNode node in element.ChildNodes)
				if (node is XmlElement)
				{
					XmlElement subElement = node as XmlElement;
					token.Add(loader.LoadExpression(subElement));
				}
			return token;
		}

		public abstract bool IsToken(XmlElement element);
	}
	public class XmlAdditionDescription : XmlBinaryOperatorDescription<XmlAddition>
	{
		public static readonly XmlAdditionDescription Instance = new XmlAdditionDescription();
		public override bool IsToken(XmlElement element) { return element.Name == "addition"; }
	}
	public class XmlSubtractionDescription : XmlBinaryOperatorDescription<XmlSubtraction>
	{
		public static readonly XmlSubtractionDescription Instance = new XmlSubtractionDescription();
		public override bool IsToken(XmlElement element) { return element.Name == "subtraction"; }
	}
	public class XmlMultiplucationDescription : XmlBinaryOperatorDescription<XmlMultiplication>
	{
		public static readonly XmlMultiplucationDescription Instance = new XmlMultiplucationDescription();
		public override bool IsToken(XmlElement element) { return element.Name == "multiplication"; }
	}
	public class XmlDivisionDescription : XmlBinaryOperatorDescription<XmlDivision>
	{
		public static readonly XmlDivisionDescription Instance = new XmlDivisionDescription();
		public override bool IsToken(XmlElement element) { return element.Name == "division"; }
	}
}
